package secondriver.springsubway.example.aop;

public aspect SimpleAspect {

	public pointcut staticInit() : staticinitialization(secondriver.springsubway.example.aop.Simple);

	before() : staticInit() {
		System.out.println("[before]"
				+ thisJoinPointStaticPart.getSignature().getName());
	}

	after() returning() : staticInit() {
		System.out.println("[after returning]"
				+ thisJoinPointStaticPart.getSignature().getName());
	}

	before() : call(public secondriver.springsubway.example.aop.*.new()) {
		System.out.println("[before]" + thisJoinPoint.getSignature().getName());
	}

	after() : call(public secondriver.springsubway.example.aop.*.new()) {
		System.out.println("[after]" + thisJoinPoint.getSignature().getName());
	}

	public pointcut welcomeMethod(String name) : call(public String secondriver.springsubway.example.aop..*.welcome(String)) && args(name);

	before(String name): welcomeMethod(name){
		System.out
				.println("[before]"
						+ thisJoinPoint.getTarget().getClass()
								.getCanonicalName() + "."
						+ thisJoinPoint.getSignature().getName()
						+ " args_name=" + name);
	}

	after(String name) returning(String retval) : welcomeMethod(name) {
		System.out.println("[after returning]"
				+ thisJoinPoint.getTarget().getClass().getCanonicalName() + "."
				+ thisJoinPoint.getSignature().getName() + " args_name=" + name
				+ " return_value =" + retval);

	}

	after(String name) : welcomeMethod(name){
		System.out
				.println("[after]"
						+ thisJoinPoint.getTarget().getClass()
								.getCanonicalName() + "."
						+ thisJoinPoint.getSignature().getName()
						+ " args_name=" + name);
	}

	after(String name) throwing(java.lang.Exception e) : welcomeMethod(name)
	 {
		System.out.println("[after throwing]"
				+ thisJoinPoint.getTarget().getClass().getCanonicalName() + "."
				+ thisJoinPoint.getSignature().getName() + " throwing="
				+ e.getMessage());
	}
	
	/*
	
	String around(String name) : welcomeMethod(name){
		System.out.println("[around]========start=========");
		System.out
				.println("[around]"
						+ thisJoinPoint.getTarget().getClass()
								.getCanonicalName() + "."
						+ thisJoinPoint.getSignature().getName()
						+ " args_name=" + name);
		String retval = proceed(name);
		System.out.println("[around]"
				+ thisJoinPoint.getTarget().getClass().getCanonicalName() + "."
				+ thisJoinPoint.getSignature().getName() + " args_name=" + name
				+ " return_value=" + retval);
		System.out.println("[around] modify return value append '!!!' = "
				+ (retval = retval + "!!!"));
		System.out.println("[around]========end=========");
		return retval;
	}
	*/
}
